from app.extensions import db
from app.modules.common.utils import JsonEncoder


class Menu(db.Model, JsonEncoder):
    __tablename__ = "menu"
    menu_id = db.Column(db.String, primary_key = True)
    menu_name = db.Column(db.String, nullable = False, unique = True)
    menu_url = db.Column(db.String)
    menu_level = db.Column(db.Integer, nullable = False, default = 1)
    menu_status = db.Column(db.Integer, nullable = False, default = 0)
    parent_menu_id = db.Column(db.String)
    child_menu_list = None
    menu_css = db.Column(db.String)

    def __init__(self, menu_id, menu_name, menu_url, menu_level, menu_status, parent_menu_id, menu_css):
        self.menu_id = menu_id
        self.menu_name = menu_name
        self.menu_url = menu_url
        self.menu_level = menu_level
        self.menu_status = menu_status
        self.parent_menu_id = parent_menu_id
        self.menu_css = menu_css

    def to_dict(self):
        return {
            'menu_id': self.menu_id,
            'menu_name': self.menu_name,
            'menu_url': self.menu_url,
            'menu_level': self.menu_level,
            'menu_status': self.menu_status,
            'parent_menu_id': self.parent_menu_id,
            'child_menu_list': self.child_menu_list,
            'menu_css': self.menu_css,
        }
